From a9ed4151bafb04a2f285bf3a89ea928594459445 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 22 Feb 2006 19:23:35 +0100 Subject: [PATCH] Change shadow_direct_map_init/clean param from vcpu to domain. Also some cleanups. Signed-off-by: Xin Li --- xen/arch/x86/hvm/hvm.c | 7 +++++-- xen/arch/x86/hvm/svm/svm.c | 7 ++++--- xen/arch/x86/hvm/svm/vmcb.c | 2 -- xen/arch/x86/hvm/vmx/vmcs.c | 1 - xen/arch/x86/hvm/vmx/vmx.c | 4 ++-- xen/arch/x86/shadow.c | 14 +++++++------- xen/arch/x86/shadow32.c | 20 ++++++++------------ xen/arch/x86/shadow_public.c | 12 ++++-------- xen/include/asm-x86/shadow.h | 4 ++-- 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 2c7569ec68..b76e5328cc 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -190,9 +190,11 @@ void hvm_setup_platform(struct domain* d) { struct hvm_domain *platform; - if (!(HVM_DOMAIN(current) && (current->vcpu_id == 0))) + if ( !HVM_DOMAIN(current) || (current->vcpu_id != 0) ) return; + shadow_direct_map_init(d); + hvm_map_io_shared_page(d); hvm_get_info(d); @@ -200,7 +202,8 @@ void hvm_setup_platform(struct domain* d) pic_init(&platform->vpic, pic_irq_request, &platform->interrupt_request); register_pic_io_hook(); - if ( hvm_apic_support(d) ) { + if ( hvm_apic_support(d) ) + { spin_lock_init(&d->arch.hvm_domain.round_robin_lock); hvm_vioapic_init(d); } diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 2c8c4a0d84..1a085e7989 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -797,12 +797,13 @@ void svm_relinquish_resources(struct vcpu *v) free_host_save_area(v->arch.hvm_svm.host_save_area); #endif - if (v->vcpu_id == 0) { + if ( v->vcpu_id == 0 ) + { /* unmap IO shared page */ struct domain *d = v->domain; - if (d->arch.hvm_domain.shared_page_va) + if ( d->arch.hvm_domain.shared_page_va ) unmap_domain_page((void *)d->arch.hvm_domain.shared_page_va); - shadow_direct_map_clean(v); + shadow_direct_map_clean(d); } destroy_vmcb(&v->arch.hvm_svm); diff --git a/xen/arch/x86/hvm/svm/vmcb.c b/xen/arch/x86/hvm/svm/vmcb.c index 51253ee666..4796adb026 100644 --- a/xen/arch/x86/hvm/svm/vmcb.c +++ b/xen/arch/x86/hvm/svm/vmcb.c @@ -444,8 +444,6 @@ void svm_do_launch(struct vcpu *v) printk("%s: phys_table = %lx\n", __func__, pt); } - shadow_direct_map_init(v); - if ( svm_paging_enabled(v) ) vmcb->cr3 = pagetable_get_paddr(v->arch.guest_table); else diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index f79be0277e..5fee564d97 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -230,7 +230,6 @@ static void vmx_do_launch(struct vcpu *v) error |= __vmwrite(GUEST_TR_BASE, 0); error |= __vmwrite(GUEST_TR_LIMIT, 0xff); - shadow_direct_map_init(v); __vmwrite(GUEST_CR3, pagetable_get_paddr(v->domain->arch.phys_table)); __vmwrite(HOST_CR3, pagetable_get_paddr(v->arch.monitor_table)); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 9b935d4df6..d0403161ef 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -81,14 +81,14 @@ void vmx_final_setup_guest(struct vcpu *v) void vmx_relinquish_resources(struct vcpu *v) { struct hvm_virpit *vpit; - + if (v->vcpu_id == 0) { /* unmap IO shared page */ struct domain *d = v->domain; if ( d->arch.hvm_domain.shared_page_va ) unmap_domain_page_global( (void *)d->arch.hvm_domain.shared_page_va); - shadow_direct_map_clean(v); + shadow_direct_map_clean(d); } vmx_request_clear_vmcs(v); diff --git a/xen/arch/x86/shadow.c b/xen/arch/x86/shadow.c index 166d026c0b..3e85cf2264 100644 --- a/xen/arch/x86/shadow.c +++ b/xen/arch/x86/shadow.c @@ -3950,11 +3950,11 @@ int shadow_direct_map_fault(unsigned long vpa, struct cpu_user_regs *regs) __direct_get_l3e(v, vpa, &sl3e); - if ( !(l3e_get_flags(sl3e) & _PAGE_PRESENT) ) + if ( !(l3e_get_flags(sl3e) & _PAGE_PRESENT) ) { page = alloc_domheap_page(NULL); if ( !page ) - goto nomem; + goto nomem; smfn = page_to_mfn(page); sl3e = l3e_from_pfn(smfn, _PAGE_PRESENT); @@ -3968,11 +3968,11 @@ int shadow_direct_map_fault(unsigned long vpa, struct cpu_user_regs *regs) __direct_get_l2e(v, vpa, &sl2e); - if ( !(l2e_get_flags(sl2e) & _PAGE_PRESENT) ) + if ( !(l2e_get_flags(sl2e) & _PAGE_PRESENT) ) { page = alloc_domheap_page(NULL); if ( !page ) - goto nomem; + goto nomem; smfn = page_to_mfn(page); sl2e = l2e_from_pfn(smfn, __PAGE_HYPERVISOR | _PAGE_USER); @@ -3985,11 +3985,11 @@ int shadow_direct_map_fault(unsigned long vpa, struct cpu_user_regs *regs) __direct_get_l1e(v, vpa, &sl1e); - if ( !(l1e_get_flags(sl1e) & _PAGE_PRESENT) ) + if ( !(l1e_get_flags(sl1e) & _PAGE_PRESENT) ) { sl1e = l1e_from_pfn(mfn, __PAGE_HYPERVISOR | _PAGE_USER); __direct_set_l1e(v, vpa, &sl1e); - } + } shadow_unlock(d); return EXCRET_fault_fixed; @@ -3998,7 +3998,7 @@ fail: return 0; nomem: - shadow_direct_map_clean(v); + shadow_direct_map_clean(d); domain_crash_synchronous(); } #endif diff --git a/xen/arch/x86/shadow32.c b/xen/arch/x86/shadow32.c index 5264b0359b..916cc3c09e 100644 --- a/xen/arch/x86/shadow32.c +++ b/xen/arch/x86/shadow32.c @@ -1044,7 +1044,7 @@ int shadow_direct_map_fault(unsigned long vpa, struct cpu_user_regs *regs) } shadow_lock(d); - + __direct_get_l2e(v, vpa, &sl2e); if ( !(l2e_get_flags(sl2e) & _PAGE_PRESENT) ) @@ -1059,7 +1059,7 @@ int shadow_direct_map_fault(unsigned long vpa, struct cpu_user_regs *regs) sple = (l1_pgentry_t *)map_domain_page(smfn); memset(sple, 0, PAGE_SIZE); __direct_set_l2e(v, vpa, sl2e); - } + } if ( !sple ) sple = (l1_pgentry_t *)map_domain_page(l2e_get_pfn(sl2e)); @@ -1082,36 +1082,32 @@ fail: return 0; nomem: - shadow_direct_map_clean(v); + shadow_direct_map_clean(d); domain_crash_synchronous(); } -int shadow_direct_map_init(struct vcpu *v) +int shadow_direct_map_init(struct domain *d) { struct page_info *page; l2_pgentry_t *root; if ( !(page = alloc_domheap_page(NULL)) ) - goto fail; + return 0; root = map_domain_page(page_to_mfn(page)); memset(root, 0, PAGE_SIZE); unmap_domain_page(root); - v->domain->arch.phys_table = mk_pagetable(page_to_maddr(page)); + d->arch.phys_table = mk_pagetable(page_to_maddr(page)); return 1; - -fail: - return 0; } -void shadow_direct_map_clean(struct vcpu *v) +void shadow_direct_map_clean(struct domain *d) { int i; unsigned long mfn; - struct domain *d = v->domain; l2_pgentry_t *l2e; mfn = pagetable_get_pfn(d->arch.phys_table); @@ -1143,7 +1139,7 @@ int __shadow_mode_enable(struct domain *d, unsigned int mode) if(!new_modes) /* Nothing to do - return success */ return 0; - + // can't take anything away by calling this function. ASSERT(!(d->arch.shadow_mode & ~mode)); diff --git a/xen/arch/x86/shadow_public.c b/xen/arch/x86/shadow_public.c index 7dfe111f2f..82aa9b002e 100644 --- a/xen/arch/x86/shadow_public.c +++ b/xen/arch/x86/shadow_public.c @@ -36,31 +36,27 @@ static void free_p2m_table(struct vcpu *v); #define SHADOW_MAX_GUEST32(_encoded) ((L1_PAGETABLE_ENTRIES_32 - 1) - ((_encoded) >> 16)) -int shadow_direct_map_init(struct vcpu *v) +int shadow_direct_map_init(struct domain *d) { struct page_info *page; l3_pgentry_t *root; if ( !(page = alloc_domheap_pages(NULL, 0, ALLOC_DOM_DMA)) ) - goto fail; + return 0; root = map_domain_page(page_to_mfn(page)); memset(root, 0, PAGE_SIZE); root[PAE_SHADOW_SELF_ENTRY] = l3e_from_page(page, __PAGE_HYPERVISOR); - v->domain->arch.phys_table = mk_pagetable(page_to_maddr(page)); + d->arch.phys_table = mk_pagetable(page_to_maddr(page)); unmap_domain_page(root); return 1; - -fail: - return 0; } -void shadow_direct_map_clean(struct vcpu *v) +void shadow_direct_map_clean(struct domain *d) { unsigned long mfn; - struct domain *d = v->domain; l2_pgentry_t *l2e; l3_pgentry_t *l3e; int i, j; diff --git a/xen/include/asm-x86/shadow.h b/xen/include/asm-x86/shadow.h index 6c41b9b3f1..a9e3789f8d 100644 --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -115,8 +115,8 @@ do { \ #define SHADOW_ENCODE_MIN_MAX(_min, _max) ((((GUEST_L1_PAGETABLE_ENTRIES - 1) - (_max)) << 16) | (_min)) #define SHADOW_MIN(_encoded) ((_encoded) & ((1u<<16) - 1)) #define SHADOW_MAX(_encoded) ((GUEST_L1_PAGETABLE_ENTRIES - 1) - ((_encoded) >> 16)) -extern void shadow_direct_map_clean(struct vcpu *v); -extern int shadow_direct_map_init(struct vcpu *v); +extern void shadow_direct_map_clean(struct domain *d); +extern int shadow_direct_map_init(struct domain *d); extern int shadow_direct_map_fault( unsigned long vpa, struct cpu_user_regs *regs); extern void shadow_mode_init(void); -- 2.30.2